package ten;


import static util.Print.print;

/**
 * Created by ab on 2016/11/4.
 */

public class task2 {
    private Object[] items;
    private int next = 0;

    public task2(int size) {
        items = new Object[size];
    }

    public void add(Object x) {
        if (next < items.length)
            items[next++] = x;
    }

    private class SequenceSelector implements Selector {
        private int i = 0;

        @Override
        public boolean end() {
            return i == items.length;
        }

        @Override
        public Object current() {
            return items[i];
        }

        @Override
        public void next() {
            if (i < items.length) i++;
        }
    }

    public Selector selector() {
        return new SequenceSelector();
    }

    static class SomeString {
        private String value;

        SomeString(String s) {
            value = s;
        }

        public String toString() {
            return value.toString();
        }
    }


    public static void main(String[] args) {
        task2 t = new task2(3);
        t.add(new SomeString("ass"));
        t.add(new SomeString("we"));
        t.add(new SomeString("can"));
        Selector selector = t.selector();
        while (!selector.end()) {
            print(selector.current() + " ");
            selector.next();
        }
    }
}
